#!/usr/bin/env python

import os.path as path
import json

def FileCache(filename):
    def __file_cache_wrapper(func):
        def file_cached_func(*args, **kwargs):
            if path.isfile(filename):
                with open(filename) as f:
                    return f.read()
            else:
                with open(filename, "w") as f:
                    result = func(*args, **kwargs)
                    json.dump(result, f)
                    return result
        return file_cached_func
    return __file_cache_wrapper
